﻿@page "/blog/add"

@using Blog.MVP.Blazor.Models

@inject HttpClient Http
@inject NavigationManager NavManager
@using  Blog.MVP.Blazor.Pages.Blogs.component

<h1>添加</h1>

<Editor OnSaveCallback="OnSaveAsync"></Editor>


<div class="text-danger">
    @_errmsg
</div>

@code {

    private BlogArticle BlogArticle { get; set; }

    private string _errmsg;

    protected override Task OnInitializedAsync()
    {
        return base.OnInitializedAsync();
    }

    private async Task OnSaveAsync(BlogArticle blogArticle)
    {
        BlogArticle = blogArticle;
        var result = await Http.PostAsJsonAsync("/api/Blog", BlogArticle);

        if (result.IsSuccessStatusCode)
        {
            NavManager.NavigateTo("/blog/list");
        }
        else
        {
            _errmsg = "保存失败";
        }
    }

}